package com.core.dao.mybatismysql;

import com.core.bean.User;
import com.core.dao.IUserDao;
import com.core.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

public class UserDao implements IUserDao {
    @Override
    public int add(User entity) throws Exception {
        SqlSession session = MybatisUtils.getSession();
        IUserDao iUserDao = session.getMapper(IUserDao.class);
        int add = iUserDao.add(entity);
        return add;
    }

    @Override
    public int remove(String id) throws Exception {
        SqlSession session = MybatisUtils.getSession();
        IUserDao iUserDao = session.getMapper(IUserDao.class);
        int remove = iUserDao.remove(id);
        return remove;
    }

    @Override
    public int modify(User entity) throws Exception {
        SqlSession session = MybatisUtils.getSession();
        IUserDao iUserDao = session.getMapper(IUserDao.class);
        int modify = iUserDao.modify(entity);
        return modify;
    }

    @Override
    public User findEntityById(String id) throws Exception {
        SqlSession session = MybatisUtils.getSession();
        IUserDao iUserDao = session.getMapper(IUserDao.class);
        User entityById = iUserDao.findEntityById(id);
        return entityById;
    }

    @Override

    public User findByName(String name) {
        SqlSession session = MybatisUtils.getSession();
        IUserDao iUserDao = session.getMapper(IUserDao.class);
        return iUserDao.findByName(name);

    }
}
